<template>
	<view class="main-box">
		<view class="navigator-bar" :style="{'padding-top': safeTop + 'px'}">
			<image class="back-img" src="/static/close1.png" @click="back()"></image>
			<text class="page-title">选择成员</text>
		</view>
		<scroll-view class="user-list" scroll-y="true" :style="{'height': `calc(100vh - ${safeTop}px - 86rpx)`}">
			<view class="user-item" v-for="user of userList" @click="chooseUsers(user.id)">
				<view class="img-box">
					<image class="user-avatar" :src="user.avatar"></image>
					<view class="over-box" v-if="chooseUser.includes(user.id)"></view>
					<view class="choose-box" v-if="chooseUser.includes(user.id)">
						<image class="choose-img" src="/static/picChoosed.png"></image>
					</view>
				</view>
				<view class="name-text">{{ user.nickName }}</view>
			</view>
			<view style="height: 160rpx;"></view>
		</scroll-view>
		<view class="remove-button" :style="{'bottom': `calc(${safeBottom}px + 60rpx)`}" @click="removeUser()">移除</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userList: [],
				chooseUser: [],
				safeTop: 0,
				safeBottom: 0,
				activityId: 0
			};
		},
		onLoad(q) {
			this.safeTop = this.$safeTop;
			this.safeBottom = this.$safeBottom;
			this.activityId = q.id;
			uni.$on('removeUser', (userList) => {
				this.userList = userList;
			})
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			chooseUsers(id) {
				if (this.chooseUser.includes(id)) {
					let index = this.chooseUser.findIndex(item => item === id);
					this.chooseUser.splice(index, 1);
				} else {
					this.chooseUser.push(id);
				}
			},
			removeUser() {
				const params = {
					activityId: this.activityId,
					ids: this.chooseUser.join(',')
				}
				this.$apis.deleteActivityUsers(params).then(res => {
					if (res.code === 0) {
						uni.showToast({
							title: '移除成功!',
							icon: 'success'
						});
						uni.$emit('editActivity', this.activity.id);
						uni.navigateBack();
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.main-box {
		width: 100vw;
		height: 100vh;
		background-color: white;
		overflow: hidden;

		.navigator-bar {
			width: 100vw;
			height: 86rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.back-img {
				width: 36rpx;
				height: 36rpx;
				margin-left: 42rpx;
				z-index: 999;
			}

			.page-title {
				font-size: 38rpx;
				font-weight: bold;
				color: #222222;
				position: absolute;
				width: 100vw;
				line-height: 38rpx;
				text-align: center;
			}
		}
		
		.user-list {
			display: flex;
			flex-wrap: wrap;
			justify-content: flex-start;
			
			.user-item {
				width: 100rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 48rpx 36rpx 0 48rpx;
				
				.img-box {
					position: relative;
					
					.user-avatar {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50rpx;
					}
					
					.over-box {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50rpx;
						position: absolute;
						top: 0;
						left: 0;
						background-color: rgba(255, 255, 255, 0.5);
						z-index: 99;
					}
					
					.choose-box {
						position: absolute;
						bottom: 0;
						right: 0;
						z-index: 199;
						
						.choose-img {
							width: 40rpx;
							height: 40rpx;
						}
					}
				}
				
				.name-text {
					width: 100rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #222222;
					margin-top: 10rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}
		
		.remove-button {
			width: 590rpx;
			height: 100rpx;
			background: #FF5E2E;
			border-radius: 24rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 100rpx;
			text-align: center;
			position: absolute;
			left: 80rpx;
		}
	}
</style>
